<?php
namespace app\common\logic;
use think\Model;
use app\common\model\SscKjjglist;

class Hk6 extends Model
{
    protected  $ssckjjglist=[];
    public $shengxiao_data = [];
    public $wuxing_data  = [];
    public $bose_data = [];
    public $duanwei_data = [];



    protected function initialize()
    {
        parent::initialize();

        //生肖，波色
        $this->shengxiao_data = config('hk6.ZODIAC');
        $this->bose_data = config('hk6.BOSE');
        $this->duanwei_data = config('hk6.DAN');
        $this->ssckjjglist=new SscKjjglist();
    }
    /**
     ** added by lss@2017/07/25
     ** 数据处理
     ** @param $dat_codes
     ** return array
     **/
    public function dataFormat($dat_codes='')
    {

        $dat_codes_array = getCodeArr($dat_codes);
        foreach($dat_codes_array as $dat_k=>$dat_codes_single)
        {
            unset($dat_codes_array[$dat_k]);
            $dat_codes_array[$dat_k]['code'] = $dat_codes_single;
            $dat_codes_array[$dat_k]['shengxiao'] = $this->shengxiao_data[$dat_codes_single];
            $dat_codes_array[$dat_k]['bose'] = $this->bose_data[$dat_codes_single];

        }

        return $dat_codes_array;
    }


    /**
     ** 连肖判断会用到的
     ** @param $data_single[array 单个期的开奖数据]
     **/
    public function sxMatch($data_single)
    {
        $data_single_new = [];
        $shengxiao_match = array(
            '鼠' => '0',
            '牛' => '1',
            '虎' => '2',
            '兔' => '3',
            '龙' => '4',
            '蛇' => '5',
            '马' => '6',
            '羊' => '7',
            '猴' => '8',
            '鸡' => '9',
            '狗' => '10',
            '猪' => '11',
            '杂项' => '99'
        );

        //$data_single['shengxiao'] = array('虎','牛','羊','猪','鸡','牛','鸡');

        for($i=0;$i<=6;$i++)
        {
            $current = $data_single['shengxiao'][$i];
            ($i-1<0)?$prev='杂项':$prev = $data_single ['shengxiao'][$i-1];
            ($i+1>6)?$next='杂项':$next = $data_single['shengxiao'][$i+1];

            if(abs($shengxiao_match[$current]-$shengxiao_match[$prev]) == 1)
            {
                $data_single_new[$i] = '<span style="color:red">'.$data_single['shengxiao'][$i].'</span>';
                $data_single_new[$i-1] = '<span style="color:red">'.$data_single['shengxiao'][$i-1].'</span>';
            }else
            {
                if(!isset($data_single_new[$i]))
                {
                    $data_single_new[$i] = '<span>'.$data_single['shengxiao'][$i].'</span>';
                }

                if(!isset($data_single_new[$i-1]))
                {
                    $data_single_new[$i-1] = '<span>'.$data_single['shengxiao'][$i-1].'</span>';
                }
            }

            if(abs($shengxiao_match[$next] - $shengxiao_match[$current]) == 1)
            {
                $data_single_new[$i] = '<span style="color:red">'.$data_single['shengxiao'][$i].'</span>';
                $data_single_new[$i+1] = '<span style="color:red">'.$data_single['shengxiao'][$i+1].'</span>';
            }else
            {
                if(!isset($data_single_new[$i+1]))
                {
                    $data_single_new[$i+1] = '<span>'.$data_single['shengxiao'][$i+1]. '</span>';
                }
            }
        }  //for结束
        return $data_single_new;
    }

}
?>